package com.zznzzn.myweb.util;

import com.zznzzn.myweb.pojo.RespModel;
import org.springframework.http.HttpStatus;

public class RespHelper {


    public static <T> RespModel<T> buildSuccess(T data){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.OK.value());
        model.setData(data);
        model.setStatus(HttpStatus.OK.getReasonPhrase());
        model.setMsg(HttpStatus.OK.getReasonPhrase());

        return model;
    }

    public static <T> RespModel<T> buildSuccess(String msg){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.OK.value());
        model.setStatus(HttpStatus.OK.getReasonPhrase());
        model.setMsg(msg);

        return model;
    }
    public static <T> RespModel<T> buildSuccess(String msg,T data){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.OK.value());
        model.setData(data);
        model.setStatus(HttpStatus.OK.getReasonPhrase());
        model.setMsg(msg);

        return model;
    }
    public static <T> RespModel<T> buildFailure(String msg){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.BAD_REQUEST.value());

        model.setStatus(HttpStatus.BAD_REQUEST.getReasonPhrase());
        model.setMsg(msg);

        return model;
    }
    public static <T> RespModel<T> buildFailure(String msg,T data){
        RespModel<T> model = new RespModel<T>();
        model.setData(data);
        model.setCode(HttpStatus.BAD_REQUEST.value());
        model.setStatus(HttpStatus.BAD_REQUEST.getReasonPhrase());
        model.setMsg(msg);

        return model;
    }
    public static <T> RespModel<T> buildUnauthorizated(){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.UNAUTHORIZED.value());
        model.setStatus(HttpStatus.UNAUTHORIZED.getReasonPhrase());
        model.setMsg(HttpStatus.UNAUTHORIZED.getReasonPhrase());

        return model;
    }
    public static <T> RespModel<T> buildNotFound(){
        RespModel<T> model = new RespModel<T>();

        model.setCode(HttpStatus.NOT_FOUND.value());
        model.setStatus(HttpStatus.NOT_FOUND.getReasonPhrase());
        model.setMsg(HttpStatus.NOT_FOUND.getReasonPhrase());

        return model;
    }
}
